
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using BusinessObject;

namespace Autenticazione
{
	public class Club : Page
	{
		protected HtmlForm form1;
		protected Label msgLoggedUser;
		protected Label lblClub;
		protected TextBox txtClub;
		protected RequiredFieldValidator ClubValidator;
		protected Label lblCitta;
		protected TextBox txtCitta;
		protected RequiredFieldValidator CittaValidator;
		protected Label lblRegione;
		protected DropDownList cboRegione;
		protected Label lblTelefono;
		protected TextBox txtTelefono;
		protected RequiredFieldValidator TelefonoValidator;
		protected RegularExpressionValidator RegTelefonoClub;
		protected Button btnSalva;
		protected void Page_Load(object sender, EventArgs e)
		{
			BusinessObject.Club c = new BusinessObject.Club();
			Descrizione regioni = new Descrizione(0);
			if (this.Session["EMail"] == null)
			{
				base.Response.Redirect("Autenticazione.aspx");
			}
			this.msgLoggedUser.Text = string.Format("Utente corrente: {0}", this.Session["EMail"].ToString());
			if (!base.IsPostBack)
			{
				Tools.FillCombo(this.cboRegione, regioni.GetDescriptions(0), "Id", "Description");
				BusinessObject.Club club = c.GetClub(this.Session["EMail"].ToString());
				if (club != null)
				{
					this.txtClub.Text = club.ClubDescription;
					this.txtCitta.Text = club.Citta;
					this.txtTelefono.Text = club.Telefono;
					this.cboRegione.SelectedValue = club.IdRegione.ToString();
				}
			}
		}
		protected void btnSalva_Click(object sender, EventArgs e)
		{
			BusinessObject.Club c = new BusinessObject.Club();
			if (this.Session["EMail"] == null)
			{
				base.Response.Redirect("Autenticazione.aspx");
			}
			c.EMail = this.Session["EMail"].ToString();
			c.ClubDescription = this.txtClub.Text.Replace("'", "''");
			c.Citta = this.txtCitta.Text.Replace("'", "''");
			c.IdRegione = int.Parse(this.cboRegione.SelectedValue);
			c.Telefono = this.txtTelefono.Text;
			if (this.Page.IsValid)
			{
				c.Salva();
			}
		}
	}
}
